###[view/SeatGrid.py]
from PySide6.QtWidgets import QGridLayout, QGroupBox, QPushButton

class SeatGrid(QGridLayout):  # 改为继承QGridLayout
    def __init__(self, rows=8, cols=10, on_seat_click=None, parent=None):
        """
        参数:
            rows: 行数 (默认8)
            cols: 列数 (默认10) 
            on_seat_click: 座位点击回调函数
            parent: 父级组件
        """
        super().__init__(parent)  # 初始化父类QGridLayout
        self._container = QGroupBox("出勤")
        self._container.setLayout(self)  # 将自己（QGridLayout）设置给容器
        self.rows = rows
        self.cols = cols
        self.on_seat_click = on_seat_click
        self.create_grid()
        
    def create_grid(self):
        """生成带分隔线的座位网格"""
        # 设置网格布局的水平和垂直间距（单位：像素）
        self.setHorizontalSpacing(10)  # 列间距
        self.setVerticalSpacing(15)    # 行间距
        self.setSpacing(0)  # 消除网格间距干扰
        for row in range(self.rows):
            for col in range(self.cols):
                btn = self._create_seat_button(f"{self.rows-row}{chr(65+col)}", row, col)
                self.addWidget(btn, row, col)

        
    def _create_seat_button(self, text, row, col):
        """创建单个座位按钮（保持不变）"""
        btn = QPushButton(text)
        btn.setFixedSize(60, 40)
        if self.on_seat_click:
            btn.clicked.connect(lambda _, r=row, c=col, t=text: self.on_seat_click(r, c, t))
        return btn
    